package com.manli.api.controller.wechat;

import com.manli.api.dto.OrderRefuseApply;
import com.manli.api.pojo.QueryParamsPayInfo;
import com.manli.api.pojo.QueryParamsPayInfoVo;
import com.manli.api.pojo.QueryParamsRefuseApply;
import com.manli.api.pojo.Result;
import com.manli.api.service.wechat.WechatPayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import com.manli.api.base.annotation.Permissions;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
@Api(tags = "微信支付模块")
public class WechatPayController {

	@Autowired
	WechatPayService wechatPayService;

	@ApiOperation(value="微信支付", notes="微信支付多产品以及购物车")
	@Permissions(module = "", privilege = "", typeOfAccess = Permissions.METHOD_LOGIN)
	@RequestMapping(value="/wechatpay/payForMutiProductAndBuyCar")
	public @ResponseBody Result payForMutiProductAndBuyCar(@RequestBody QueryParamsPayInfoVo vo, HttpServletRequest request) throws Exception {
		return wechatPayService.payForMutiProductAndBuyCar(vo.getQueryParamsPayInfos(),request);
	}

	@ApiOperation(value="微信支付", notes="通过主订单号更新订单信息")
	@Permissions(module = "", privilege = "", typeOfAccess = Permissions.METHOD_LOGIN)
	@RequestMapping(value="/wechatpay/updateOrderInfoByMainOrderNo")
	public @ResponseBody Result updateOrderInfoByMainOrderNo(@RequestBody QueryParamsPayInfo queryParamsPayInfo, HttpServletRequest request) throws Exception {
		return wechatPayService.updateOrderInfoByMainOrderNo(queryParamsPayInfo,request);
	}

	@ApiOperation(value="微信支付", notes="通过主订单号获取商品信息")
	@Permissions(module = "", privilege = "", typeOfAccess = Permissions.METHOD_LOGIN)
	@RequestMapping(value="/wechatpay/getGoodsInfoByMainOrderNo")
	public @ResponseBody Result getGoodsInfoByMainOrderNo(@RequestBody QueryParamsPayInfo queryParamsPayInfo, HttpServletRequest request) throws Exception {
		return wechatPayService.getGoodsInfoByMainOrderNo(queryParamsPayInfo,request);
	}


	@ApiOperation(value="微信支付", notes="微信支付待支付")
	@Permissions(module = "", privilege = "", typeOfAccess = Permissions.METHOD_LOGIN)
	@RequestMapping(value="/wechatpay/payForPreParOrder")
	public @ResponseBody Result payForPreParOrder(@RequestBody QueryParamsPayInfoVo vo,HttpServletRequest request) throws Exception {
		return wechatPayService.payForPreParOrder(vo.getQueryParamsPayInfos(),request);
	}

	@ApiOperation(value="微信支付", notes="支付成功回调")
	@Permissions(module = "", privilege = "", typeOfAccess = Permissions.METHOD_OPEN)
	@RequestMapping(value="/wechatpay/orderPayNotifyo")
	public @ResponseBody String orderPayNotify(@RequestBody String notifyData) throws Exception {
		return wechatPayService.orderPayNotify(notifyData);
	}

	@ApiOperation(value="微信支付", notes="用户申请退款")
	@Permissions(module = "", privilege = "", typeOfAccess = Permissions.METHOD_LOGIN)
	@RequestMapping(value="/wechatpay/orderRefuseApply")
	public @ResponseBody Result orderRefuseApply(@RequestBody OrderRefuseApply refuseApply,HttpServletRequest request) throws Exception {
		return wechatPayService.orderRefuseApply(refuseApply,request);
	}


	@ApiOperation(value="微信支付", notes="商户审核退款")
	@Permissions(module = "", privilege = "", typeOfAccess = Permissions.METHOD_LOGIN)
	@RequestMapping(value="/wechatpay/orderRefuseAudit")
	public @ResponseBody Result orderRefuseAudit(@RequestBody OrderRefuseApply refuseApply, HttpServletRequest request) throws Exception {
		return wechatPayService.orderRefuseAudit(refuseApply,request);
	}

	@ApiOperation(value="微信支付", notes="退款成功回调")
	@Permissions(module = "", privilege = "", typeOfAccess = Permissions.METHOD_OPEN)
	@RequestMapping(value="/wechatpay/orderRefuseNotify")
	public @ResponseBody String orderRefuseNotify(@RequestBody String notifyData) throws Exception {
		return wechatPayService.orderRefuseNotify(notifyData);
	}

	@ApiOperation(value="微信支付", notes="预定支付/预付款/直接输入金额线下支付")
	@Permissions(module = "", privilege = "", typeOfAccess = Permissions.METHOD_LOGIN)
	@RequestMapping(value="/wechatpay/payForNoGoodsOrder")
	public @ResponseBody Result payForNoGoodsOrder(@RequestBody QueryParamsPayInfo queryParamsPayInfo,HttpServletRequest request) throws Exception {
		return wechatPayService.payForNoGoodsOrder(queryParamsPayInfo,request);
	}
	//TODO 日志及分布式日志

}
